{% extends 'base.html' %}
{% load static %}
{% block title %}网上商城-提交订单{% endblock title %}

{% block content %}

	{% include 'header-con.html' %}

	<div class="search_bar clearfix">
		<a href="" class="logo fl"><img src="{% static 'images/logo.png' %}"></a>
		<div class="sub_page_name fl">|&nbsp;&nbsp;&nbsp;&nbsp;提交订单</div>
		<div class="search_con fr">
			<input type="text" class="input_text fl" name="" placeholder="搜索商品">
			<input type="button" class="input_btn fr" name="" value="搜索">
		</div>		
	</div>
	
	<h3 class="common_title">确认收货地址</h3>

	<div class="common_list_con clearfix">
		<dl>
			<dt>寄送到：</dt>
			{% for addr in addrs %}
			<dd><input type="radio" name="address" value="{{ addr.id }}" {% if addr.is_default %}checked{% endif %}>{{ addr.addr }}（{{ addr.receiver }} 收） {{ addr.phone }}</dd>
			{% endfor %}
		</dl>
		<a href="/user/address/" class="edit_site">编辑收货地址</a>

	</div>
	
	<h3 class="common_title">支付方式</h3>	
	<div class="common_list_con clearfix">
		<div class="pay_style_con clearfix">

			<input type="radio" name="pay_style" value="1" checked>
			<label class="weixin">微信支付</label>
			<input type="radio" name="pay_style" value="2">
			<label class="zhifubao"></label>
			<input type="radio" name="pay_style" value="3">
			<label class="bank">银行卡支付</label>
		</div>
	</div>

    <h3 class="common_title">优惠券</h3>
	<div class="common_list_con clearfix">
		<div class="pay_style_con clearfix">
            <input type="radio" name="use_quan" value="1"  checked class="quan" id="undo">
			<label>不使用优惠券</label>
        {% if quan != 0 %}
            <input id="quan" type="radio" name="use_quan" value="2" class="quan" style="display:block;">
			<label style="display:block;">使用{{ quan }}元优惠券</label>
        {% endif %}

		</div>
	</div>
	<h3 class="common_title">商品列表</h3>
	
	<div class="common_list_con clearfix">
		<ul class="goods_list_th clearfix">
			<li class="col01">商品名称</li>
			<li class="col02">商品单位</li>
			<li class="col03">商品价格</li>
			<li class="col04">数量</li>
			<li class="col05">小计</li>		
		</ul>
		{% for sku in skus %}
		<ul class="goods_list_td clearfix">
			<li class="col01">{{ forloop.counter  }}</li>			
			<li class="col02"><img src="{{ sku.image.url }}"></li>
			<li class="col03">{{ sku.name }}</li>
			<li class="col04">{{ sku.unite }}</li>
			<li class="col05">{{ sku.price }}元</li>
			<li class="col06" name="count" >{{ sku.count }}</li>
			<li class="col07">{{ sku.amount }}元</li>	
		</ul>
		{% endfor %}
	</div>

	<h3 class="common_title">总金额结算</h3>

	<div class="common_list_con clearfix">
		<div class="settle_con">
			<div class="total_goods_count">共<em>{{ total_count }}</em>件商品，总金额<b>{{ total_price }}元</b></div>
			<div class="transit">运费：<b>0元</b></div>
			<div class="total_pay" id="total">实付款：<b>{{ total_price }}元</b></div>
		</div>
	</div>

	<div class="order_submit clearfix">
		<a href="javascript:;" id="order_btn">提交订单</a>
	</div>
	
	<input type="hidden" id="sku_ids" value="{{ sku_ids }}">
	{% csrf_token %}


	<div class="popup_con">
		<div class="popup">
			<p>订单提交成功！</p>
		</div>
		
		<div class="mask"></div>
	</div>
	<script type="text/javascript" src="{% static 'js/jquery-1.12.4.min.js' %}"></script>
	<script type="text/javascript" src="{% static 'js/place_order.js' %}"></script>
    <script>
    var initial_total_price = {{ total_price }};
    var quan = {{ quan }};
    var total = initial_total_price;
    $(document).ready(function() {
        // 点击按钮时执行的函数
        $('#quan').on('click', function() {
           if (total >= quan){
               total-=quan
            }
           else{
               total = 0
           }
        $('#total').html('实付款：<b>' + total.toFixed(2) + '元</b>');
        });
    });

    $('input[id="undo"]').on('click', function() {
        // 恢复 total_value 为原始价格值
        total = initial_total_price;
        // 更新实付款总额为原始价格
        $('#total').html('实付款：<b>' + total.toFixed(2) + '元</b>');
    });
    </script>
{% endblock content %}